package demo7;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

// 2.自定义类实现序列化排序接口
// IntWritable :默认升序排列
// DescIntWritable：自定义 int降序排列 类
public class DescIntWritable implements WritableComparable<DescIntWritable> {
    private int value;

    public DescIntWritable() {
    }

    public DescIntWritable(int value) {
        this.value = value;
    }
    @Override
    public int compareTo(DescIntWritable o) {
        int thisValue = this.value;
        int thatValue = o.value;
        return thisValue > thatValue ? -1 : (thisValue == thatValue ? 0 : 1);
    }
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(value);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.value = dataInput.readInt();
    }

    @Override
    public String toString() {
        //return "" + value;
        return Integer.toString(this.value);
    }
    public int getValue() {
        return value;
    }
    public void setValue(int value) {
        this.value = value;
    }

}
